import React from 'react';
import store from '@/store/studentApi'

const RTKQ = () => {
  // const result = store.useGetStudentQuery() // 调用钩子发送请求
  // console.log('result',result)
  /*
  {
    "status": "fulfilled",
    "endpointName": "getStudent",
    "requestId": "EAJcphS14a8r5G5NZayQZ",
    "startedTimeStamp": 1679714792543,
    "data": {
        "data": []
    },
    "fulfilledTimeStamp": 1679714792879,
    "isUninitialized": false,
    "isLoading": false,
    "isSuccess": true,
    "isError": false,
    "currentData": {
      "data": []
    },
    "isFetching": false
  }
  */
  const {data, isSuccess, isLoading} = store.useGetStudentQuery()
  return (
    <div>
      <h2>RTKQ</h2>
      {isLoading && <p>数据加载中，请稍后。。。</p>}
      {isSuccess && data.data.map(p => <div key={p.id}>
        <span>{p.attributes.name}--</span>
        <span>{p.attributes.age}--</span>
        <span>{p.attributes.sex}--</span>
        <span>{p.attributes.address}</span>
      </div>)}
    </div>
  );
};
export default RTKQ;